home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
embedded
/
develop
/
libsrc11.arc
/
ERBLKEE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-04-27
|
2KB
|
85 lines
/* erblkee.c 4.4 */
/*F********************************************************************
FUNCTION NAME: erblkee
ACTION: Erase mulitple bytes in EEPROM. This routine will
erase as much as possible in a single operation.
If a "bulk" erase can be done, then it is done.
If bulk is not done, row erases are done when possible.
Otherwise byte erases are done.
PARAMETERS:
addr: location of EEPROM to be erased. -1 indicates
to erase the config register.
count: number of bytes to erase.
**********************************************************************/
#define EROM_SIZE 512 /* Size of EEPROM */
#define ERASE_TIME 10 /* number of milliseconds to delay for erase */
#define ERASE_CONFIG -1 /* erase config register indicator */
#define ROWSIZE 16 /* row size */
#include <hc11/io.h>
#include <hc11/config.h>
#include <hc11/directives.h>
SMALL
int erblkee(addr, count)
int addr; /* location(s) to be erased */
int count; /* number of bytes to be erased */
{
if (((count+addr)>EROM_SIZE)||(addr<ERASE_CONFIG)||(addr>=EROM_SIZE))
return(-1);
if (((count+addr)==EROM_SIZE) && (addr<=0))
{ /* erase all of EEPROM and maybe config */
HC11.PPROG = EELAT | ERASE;
if (addr == ERASE_CONFIG) /* erase config register ? */
HC11.CONFIG = 0;
else
EEPROM[0] = 0;
HC11.PPROG = EELAT | ERASE | EEPGM | EEBLK;
/* delay 10 milliseconds */
delay(ERASE_TIME);
HC11.PPROG = EELAT | ERASE;
HC11.PPROG = 0; /* enable reads of EEPROM */
}
else /* erase part of EEPROM */
{
while (count > 0)
{
if ((count>=ROWSIZE) && ((addr&(ROWSIZE-1)) == 0))
{ /* erase row */
errowee(addr);
count -= ROWSIZE;
addr += ROWSIZE;
}
else
{ /* erase byte */
count--;
erbytee(addr++);
}
} /* end of while bytes to erase... */
} /* end of erase part of EEPROM */
return(0); /* good exit... */
} /* end of erblkee */